home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vol15n11.zip / TBWIZ.ZIP / TBSAVEFO.FRM < prev    next >
Text File  |  1996-02-21  |  7KB  |  243 lines

  1. VERSION 4.00
  2. Begin VB.Form tbSaveForm 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Save Toolbar"
  5.    ClientHeight    =   1590
  6.    ClientLeft      =   2850
  7.    ClientTop       =   3315
  8.    ClientWidth     =   4515
  9.    ControlBox      =   0   'False
  10.    Height          =   1995
  11.    Left            =   2790
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   1590
  16.    ScaleWidth      =   4515
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   2970
  19.    Width           =   4635
  20.    Begin VB.CommandButton Command2 
  21.       Caption         =   "Cancel"
  22.       Height          =   270
  23.       Left            =   3480
  24.       TabIndex        =   6
  25.       Top             =   720
  26.       Width           =   975
  27.    End
  28.    Begin VB.CommandButton Command1 
  29.       Caption         =   "&Save"
  30.       Height          =   270
  31.       Left            =   3480
  32.       TabIndex        =   5
  33.       Top             =   240
  34.       Width           =   975
  35.    End
  36.    Begin VB.Frame Frame1 
  37.       Caption         =   "Select controls:"
  38.       Height          =   1335
  39.       Left            =   120
  40.       TabIndex        =   0
  41.       Top             =   120
  42.       Width           =   3135
  43.       Begin VB.ComboBox Combo1 
  44.          Height          =   315
  45.          Index           =   1
  46.          Left            =   1065
  47.          TabIndex        =   4
  48.          Text            =   "Combo1"
  49.          Top             =   840
  50.          Width           =   1815
  51.       End
  52.       Begin VB.ComboBox Combo1 
  53.          Height          =   315
  54.          Index           =   0
  55.          Left            =   1065
  56.          TabIndex        =   2
  57.          Text            =   "Combo1"
  58.          Top             =   360
  59.          Width           =   1815
  60.       End
  61.       Begin VB.Label Label1 
  62.          AutoSize        =   -1  'True
  63.          Caption         =   "ImageList:"
  64.          Height          =   195
  65.          Index           =   1
  66.          Left            =   240
  67.          TabIndex        =   3
  68.          Top             =   860
  69.          Width           =   720
  70.       End
  71.       Begin VB.Label Label1 
  72.          AutoSize        =   -1  'True
  73.          Caption         =   "Toolbar:"
  74.          Height          =   195
  75.          Index           =   0
  76.          Left            =   360
  77.          TabIndex        =   1
  78.          Top             =   390
  79.          Width           =   585
  80.       End
  81.    End
  82.    Begin MSComDlg.CommonDialog CommonDialog1 
  83.       Left            =   3720
  84.       Top             =   1080
  85.       _Version        =   65536
  86.       _ExtentX        =   847
  87.       _ExtentY        =   847
  88.       _StockProps     =   0
  89.       CancelError     =   -1  'True
  90.       DefaultExt      =   "*.tbr"
  91.       DialogTitle     =   "Save Toolbar"
  92.       Filter          =   "*.tbr | Toolbars"
  93.    End
  94. End
  95. Attribute VB_Name = "tbSaveForm"
  96. Attribute VB_Creatable = False
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99. DefInt A-Z
  100.  
  101. Function SaveTB() As Integer
  102. '___setup vars
  103. Dim ProjectFilename$, ProjectDirty As Boolean
  104. Dim CurrFormName$, CurrFormFiles$(1)
  105. Dim i%, ii%
  106. Dim success As Boolean
  107. '___get form file names
  108. With gobjIDEAppInst.ActiveProject
  109.     CurrFormName$ = .ActiveForm.Properties.Item("Name")
  110.     With .Components
  111.         For i% = 0 To .Count - 1
  112.             If .Item(i%).Name = CurrFormName$ Then
  113.                 CurrFormFiles$(0) = .Item(i%).FileNames(0)
  114.                 CurrFormFiles$(1) = .Item(i%).FileNames(1)
  115.             End If
  116.         Next
  117.     End With
  118. End With
  119. If CurrFormFiles$(0) = "" Or (Len(CurrFormFiles$(0)) = 0) Then
  120.     Alert "Save form file first!"
  121.     SaveTB = -1
  122.     Exit Function
  123. End If
  124.  
  125. '___get name of target TBR file from user
  126. On Error Resume Next
  127. CommonDialog1.ShowSave
  128. If Err = cdlCancel Then SaveTB = 0: Exit Function
  129. On Error GoTo 0
  130. gfnameTBFile = CommonDialog1.FileName
  131. Screen.MousePointer = HOURGLASS
  132.  
  133. '___more vars...
  134. Dim Source$
  135. Source$ = CurrFormFiles$(0)
  136. Dim linetest$
  137. Dim Targ$
  138. Dim tbEvent$
  139. Dim icTest$, tbTest$
  140. Dim Terminator$
  141. icTest$ = "ImageList " & Combo1(1)
  142. tbTest$ = "Toolbar " & Combo1(0)
  143. tbEvent$ = Combo1(0) & "_"
  144. Targ$ = ExtractFilePath$(gfnameTBFile) + ExtractFileRoot(gfnameTBFile) + ".tbr"
  145. Terminator$ = "End"
  146. '___copy code from frm to tbr file
  147. Open Targ$ For Output As #1
  148. Open Source$ For Input As #2
  149.     Do While Not EOF(2)
  150.         Line Input #2, linetest$
  151.         If (InStr(linetest$, icTest$) > 0) Or (InStr(linetest$, tbTest$) > 0) Then
  152.            '___we found the toolbar or imagelist
  153.             Print #1, linetest$
  154.             Do
  155.               Line Input #2, linetest$
  156.               Print #1, linetest$
  157.             Loop Until Trim$(linetest$) = Terminator$
  158.          End If
  159.      Loop
  160. Close #2
  161. '___now copy the toolbar's event handlers
  162. Terminator$ = "End Sub"
  163. Print #1, "TB_EVENTS"
  164. Open Source$ For Input As #2
  165.     Do While Not EOF(2)
  166.         Line Input #2, linetest$
  167.         If InStr(linetest$, tbEvent$) > 0 Then
  168.             '___we found a toolbar event handler
  169.             Print #1, linetest$
  170.             Do
  171.               Line Input #2, linetest$
  172.               Print #1, linetest$
  173.             Loop Until Trim$(linetest$) = Terminator$
  174.         End If
  175.     Loop
  176. Close #2
  177. Close #1
  178.  
  179. '___copy frx file
  180. Targ$ = ExtractFilePath$(gfnameTBFile) + ExtractFileRoot(gfnameTBFile) + ".frx"
  181. FileCopy ExtractFilePath$(Source$) + ExtractFileRoot(Source$) + ".frx", Targ$
  182. SaveTB = 1
  183. End Function
  184.  
  185. Private Sub Command1_Click()
  186. Select Case SaveTB()
  187. Case -1 'form hasn't been saved
  188. Case 0  'canceled
  189. Case 1  'success
  190. End Select
  191. Screen.MousePointer = DEFAULT
  192. Unload Me
  193.  
  194. End Sub
  195.  
  196.  
  197. Private Sub Command2_Click()
  198. Unload Me
  199. End Sub
  200.  
  201. Private Sub Form_Initialize()
  202.  
  203. End Sub
  204.  
  205. Private Sub Form_Load()
  206. WinCenter Me
  207. Dim i%, testControl As Object
  208. '___add names of toolbars and imagelists to dialog's combo boxes
  209. With gobjIDEAppInst.ActiveProject.ActiveForm
  210.  For i% = 0 To .ControlTemplates.Count - 1
  211.   Set testControl = .ControlTemplates(i)
  212.   Select Case testControl
  213.     Case Is = "ComctlLib.ImageList"
  214.         Combo1(1).AddItem testControl.Properties.Item("Name")
  215.     Case Is = "ComctlLib.Toolbar"
  216.         Combo1(0).AddItem testControl.Properties.Item("Name")
  217.     Case Else
  218.   End Select
  219.  Next i%
  220. End With
  221. '___can't save a toolbar if you don't have one
  222. If (Combo1(0).ListCount * Combo1(1).ListCount) = 0 Then
  223.         Alert "You need to add a toolbar and/or Imagelist control to this form."
  224.         Exit Sub
  225. End If
  226. Combo1(0).ListIndex = 0
  227. Combo1(1).ListIndex = 0
  228. '___bring nonmodal dialog to top
  229. Show
  230. Me.SetFocus
  231.  
  232. Dim VBCap$
  233. VBCap$ = ExtractFileRoot$(gobjIDEAppInst.ActiveProject.FileName)
  234. SetParentByCaption VBCap$, hwnd
  235. End Sub
  236.  
  237.  
  238. Private Sub Form_Paint()
  239.  
  240. End Sub
  241.  
  242.  
  243.